// The Vue build version to load with the `import` command
// (runtime-only or standalone) has been set in webpack.base.conf with an alias.
import Vue from 'vue'
import ElementUI from 'element-ui'
import 'element-ui/lib/theme-chalk/index.css'
import App from './App'
import router from './router'
import store from './store/index.js';
import axios from 'axios'
import qs from 'qs'
Vue.prototype.$qs = qs
// 将请求方法绑定到Vue的原型之上
import {
  post,
  fetch,
  patch,
  put,
  jqGet,
  jqPost
} from './network/network';

import api from './network/api';


import '@/lib/jquery-1.11.0.min.js';
// import '@/lib/anime.min.js';
// import '@/lib/particles.js';

import 'video.js/dist/video-js.css';



/**
 * 时间格式化函数, 按照指定格式化字符串格式化传入时间
 *
 * @param {Date} time 需要格式化的时间
 * @param {String} fmStr 定义时间的格式
 * 		yyyy: 代表四位数年份
 * 		  yy: 代表两位数年份
 * 		  mm: 代表月份(小于10时补0)
 * 		  dd: 代表日期(小于10时补0)
 * 		  hh: 代表小时(小于10时补0)
 * 		  hh: 代表小时(小于10时补0)
 * 		  MM: 代表分钟(小于10时补0)
 * 		  ss: 代表秒数(小于10时补0)
 * 		 SSS: 代表毫秒数
 * 		   w: 代表周几(数字)
 * 		   W: 代表周几(中文)
 * 		  ww: 代表周几(英文)
 * @returns {String} 返回格式化的时间
 */
function timeFormat(time, fmStr) {
  const weekCN = '一二三四五六日';
  const weekEN = ['Monday', 'Tuesday', 'Wednesday', 'Thursday', 'Friday', 'Saturday', 'Sunday'];

  let year = time.getFullYear();
  let month = time.getMonth() + 1;
  let day = time.getDate();
  let hours = time.getHours();
  let minutes = time.getMinutes();
  let seconds = time.getSeconds();
  let milliSeconds = time.getMilliseconds();
  let week = time.getDay();

  month = month >= 10 ? month : ('0' + month);
  day = day >= 10 ? day : ('0' + day);
  hours = hours >= 10 ? hours : ('0' + hours);
  minutes = minutes >= 10 ? minutes : ('0' + minutes);
  seconds = seconds >= 10 ? seconds : ('0' + seconds);

  if (fmStr.indexOf('yyyy') !== -1) {
    fmStr = fmStr.replace('yyyy', year);
  } else {
    fmStr = fmStr.replace('yy', (year + '').slice(2));
  }
  fmStr = fmStr.replace('mm', month);
  fmStr = fmStr.replace('dd', day);
  fmStr = fmStr.replace('hh', hours);
  fmStr = fmStr.replace('MM', minutes);
  fmStr = fmStr.replace('ss', seconds);
  fmStr = fmStr.replace('SSS', milliSeconds);
  fmStr = fmStr.replace('W', weekCN[week - 1]);
  fmStr = fmStr.replace('ww', weekEN[week - 1]);
  fmStr = fmStr.replace('w', week);
  return fmStr;
}

Date.prototype.format = function(fmStr){
  return timeFormat(this, fmStr);
}




Vue.use(ElementUI);
Vue.config.productionTip = false

Vue.prototype.$axios = axios;
Vue.prototype.$api = api;
Vue.prototype.$post = post;
Vue.prototype.$get = fetch;
Vue.prototype.$patch = patch;
Vue.prototype.$put = put;
Vue.prototype.$jquery = $;
Vue.prototype.$jqGet = jqGet;
Vue.prototype.$jqPost = jqPost;

/* eslint-disable no-new */
new Vue({
  el: '#app',
  router,
  store,
  components: {
    App
  },
  template: '<App/>'
})
